function getUuid() {
    return Ext.create("MyApp.data.MyModelX").data.id.replace(/-/g, "");
};

//下载附件
function fileDownload(downloadURL) {
    var tempForm = document.createElement("form");
    tempForm.type = "hidden";
    tempForm.style = 'display:none';
    tempForm.action = downloadURL;
    document.getElementById('app').appendChild(tempForm); // 将表单放置在web中
    tempForm.submit(); // 表单提交
    tempForm.remove(); // 表单移除
}

Ext.Ajax.request({//获取这个用户的用户名和Id
    url: zuulUrl + '/' + authServiceName + '/user/realName',
    method: 'get',
    async: false, //ASYNC 是否异步( TRUE 异步 , FALSE 同步)
    success: function (response, opts) {
        var obj = Ext.JSON.decode(response.responseText);
        currentUser = obj.realName;
        currentUserId = obj.userId;
    },
    failure: function (response, opts) {
        console.log('server-side failure with status code ' + response.status);
    }
});

Ext.Ajax.request({//去缓存里获取这个用户当前进入的项目,老师和主任也会去获取，但是因为用不到，所以没事
    url: zuulUrl + '/' + webServiceName + '/cache/inProject/' + currentUserId,
    method: 'get',
    async: false, //ASYNC 是否异步( TRUE 异步 , FALSE 同步)
    success: function (response, opts) {
        currentProjectId = response.responseText;
        testRequirementProject = response.responseText;
        testDesignProject = response.responseText;
        testRunProject = response.responseText;
    },
    failure: function (response, opts) {
        console.log('server-side failure with status code ' + response.status);
    }
});

function delChooseProjectCache() {
    Ext.Ajax.request({//清除缓存里这个用户当前进入的项目,老师和主任也会去清除，但是因为用不到，所以没事
        url: zuulUrl + '/' + webServiceName + '/cache/inProject/' + currentUserId,
        method: 'delete',
        async: false, //ASYNC 是否异步( TRUE 异步 , FALSE 同步)
        success: function (response, opts) {
        },
        failure: function (response, opts) {
            console.log('server-side failure with status code ' + response.status);
        }
    });
}

//用于用户注销登陆
function userLogout() {
    delChooseProjectCache();//清除缓存里这个用户当前进入的项目,老师和主任也会去清除，但是因为用不到，所以没事
    var form = document.createElement("form");
    form.action = zuulUrl + '/' + authServiceName + '/logout'
    form.method = 'post';
    // 将form放到body中
    document.body.appendChild(form);
    // 提交表单
    form.submit();
    // 清除from
    document.body.removeChild(form)
}

//用于更改页面右上方的tripButton的用户名
function updateUserTripButtonText(text) {
    Ext.getCmp('viewPort').down('#userTripButton').setText('hi ~ ' + text);
    Ext.getCmp('viewPort').down('#userTripButton').setTooltip('当前用户:' + text);
}

//获取某个用户今天这个项目打卡了多少次
function getUserProjectCheckOnWorkTimeToday() {
    Ext.Ajax.request({
        url: zuulUrl + '/' + testServiceName + '/checkOnWork/' + currentProjectId + '/' + currentUserId,
        method: 'get',
        async: false, //ASYNC 是否异步( TRUE 异步 , FALSE 同步)
        success: function (response, opts) {
            var count = response.responseText;
            var viewPort = Ext.getCmp('viewPort');
            viewPort.down('#checkOnWorkButton').setText('签到(今日已签到' + count + '次)');
            viewPort.down('#checkOnWorkButton').setDisabled(count >= 5);
        },
        failure: function (response, opts) {
            var obj = Ext.decode(response.responseText);
            if (obj.code == 408)
                Ext.Msg.alert("错误", obj.message);
            else
                Ext.Msg.alert("错误", "获取签到次数失败！");
        }
    });
}

//获取某个树节点在整棵树的全路径
function getItemInTreePath(treeStore,record) {
    var pathArray = new Array(),
        parentId = record.get('parentId'), itemNode = record,
        path = '';
    while (parentId != 'root') {//获取测试计划全路径
        itemNode = treeStore.getNodeById(parentId);
        pathArray.push(itemNode.get('text'));
        parentId = itemNode.get('parentId');
    }
    for (var i = pathArray.length - 1; i >= 0; i--) {
        path = path + pathArray[i] + '/';
    }
    return path + record.get('text');
}